// 
// SoapTrace.Net - A soap message monitoring utility. 
// 
// Copyright (C) 2004 Matthew Ward
// 
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
// 
// Matthew Ward (mrward@users.sourceforge.net)
// 

using NUnit.Framework;
using System;
using System.Diagnostics;
using WinPcap;
using WinPcap.Tests.Utils;
using WinPcap.Tests.Configuration;

namespace WinPcap.Tests
{
	/// <summary>
	/// Tests the WinPCap.net network interface list.
	/// </summary>
	[ TestFixture ]
	public class NetworkInterfaceListTestFixture
	{
		/// <summary>
		/// The network interface list to test.
		/// </summary>
		private NetworkInterfaceCollection m_NetworkInterfaces;

		/// <summary>
		/// Initialises this test.
		/// </summary>
		[ SetUp ]
		public void Init( )
		{
			m_NetworkInterfaces = NetworkInterface.GetAllNetworkInterfaces( );
		}

		/// <summary>
		/// Checks that the correct amount of network interfaces
		/// are read.
		/// </summary>
		[ Test ]
		public void NetworkInterfaceCount( )
		{
			Assert.AreEqual( TestConfig.NetworkInterfaces.Count, 
				m_NetworkInterfaces.Count, 
				"Expected network interface count does not match actual." );
		}

		/// <summary>
		/// Tests the reading of network interface names.
		/// </summary>
		[ Test ]
		public void ExpectedNetworkInterfaces( )
		{
			for( int i = 0; i < TestConfig.NetworkInterfaces.Count; ++i )
			{
				TestUtility.CompareNetworkInterfaceInfo( 
					TestConfig.NetworkInterfaces[ i ],
					m_NetworkInterfaces[ i ] );
			}
		}

		/// <summary>
		/// Ensures that we have at the expected number of
		/// network addresses.
		/// </summary>
		[ Test ]
		public void ExpectedNetworkInterfaceAddressCount( )
		{
			NetworkInterfaceInfo NetworkInterface = TestConfig.NetworkInterfaces[ 0 ];

			for( int i = 0; i < m_NetworkInterfaces.Count; ++i )
			{
				NetworkInterfaceAddressCollection Addresses = 
					m_NetworkInterfaces[ i ].Addresses;

				NetworkInterfaceAddressInfoCollection ExpectedAddresses =
					TestConfig.NetworkInterfaces[ i ].NetworkInterfaceAddresses;

				Assert.AreEqual( ExpectedAddresses.Count,
					Addresses.Count,
				                String.Concat( "Expected network interface address ", 
				                              i.ToString( ), " is incorrect." ) );
			}
		}

		/// <summary>
		/// Checks that the read in network interface addresses match
		/// our expected values.
		/// </summary>
		[ Test ]
		public void ExpectedNetworkInterfaceAddresses( )
		{
			for( int i = 0; i < m_NetworkInterfaces.Count; ++i )
			{
				NetworkInterfaceInfo ExpectedNetworkInterface = 
					TestConfig.NetworkInterfaces[ i ];

				NetworkInterface ActualNetworkInterface = 
					m_NetworkInterfaces[ i ];

				// Compare each of the network interface address objects.

				for( int j = 0; 
					j < ActualNetworkInterface.Addresses.Count; 
					++j )
				{
					TestUtility.CompareNetworkInterfaceAddressInfo( 
						ExpectedNetworkInterface.NetworkInterfaceAddresses[ j ],
						ActualNetworkInterface.Addresses[ j ] );
				}
			}
		}

	}
}
